﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                xmlns:fn="http://www.w3.org/2005/xpath-functions" 
                xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" 
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                xmlns:o="urn:schemas-microsoft-com:office:office" 
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" 
                xmlns:v="urn:schemas-microsoft-com:vml" 
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" 
                xmlns:w10="urn:schemas-microsoft-com:office:word" 
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" 
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" 
                xmlns:a="http://www.tei-c.org/ns/1.0"
                exclude-result-prefixes="xs fn xdt ve o r m v wp w10 w wne a">
  <xsl:output method="xml" version="1.0" indent="yes"/>
  
  <xsl:template name="endnoteref" match="a:note[@place='end']">
    <xsl:variable name="numENote">
      <xsl:number level="any" format="1"/>
    </xsl:variable>
    <w:r>
      <w:rPr>
        <w:rStyle w:val="EndnoteReference"/>
      </w:rPr>
      <w:endnoteReference w:id="{$numENote+1}"/>
    </w:r>
  </xsl:template>
  
  <xsl:template name="endnotetext">
    <xsl:for-each select="//a:note[@place='end']">
      <xsl:variable name="numENote">
        <xsl:number level="any" format="1"/>
      </xsl:variable>
      <w:endnote>
        <xsl:attribute name="w:id">
          <xsl:value-of select="$numENote+1"/>
        </xsl:attribute>
        <w:p>
	        <w:pPr>
		        <w:pStyle w:val="EndnoteText"/>
	        </w:pPr>
	        <w:r>
		        <w:rPr>
			        <w:rStyle w:val="EndnoteReference"/>
		        </w:rPr>
		        <w:endnoteRef/>
	        </w:r>
	        <w:r>
		        <w:t>
              <xsl:value-of select="."/>
            </w:t>
	        </w:r>
        </w:p>
      </w:endnote>
    </xsl:for-each>
  </xsl:template>
  

  </xsl:stylesheet>